package com.hk.service.impl;

import org.springframework.stereotype.Service;

import com.hk.commons.HqlFilter;
import com.hk.commons.StringHelper;
import com.hk.commons.entity.Province;
import com.hk.dao.base.impl.BaseServiceImpl;
import com.hk.service.sys.IProvince;

@Service
public class ProvinceImpl extends BaseServiceImpl<Province> implements IProvince {

	@Override
	public Province findById(Integer id) {
		return getById(id);
	}

	@Override
	public void add(Province model) {
		
		super.save(model);
	}

	@Override
	public Province delete(Integer id) {
		Province model = new Province();
		model.setId(id);
		delete(model);
		return model;
	}

	@Override
	public Boolean existById(Integer ProvinceId) {

		Province Province = getById(ProvinceId);
		return Province != null;
	}

	@Override
	public String getProvinceNameById(Integer ProvinceId) {
		String ProvinceName = "";
		Province Province = getById(ProvinceId);
		if (Province != null) {
			ProvinceName = Province.getProName();
		}
		return ProvinceName;
	}

	@Override
	public Integer getProvinceIdByCode(String proCode) {

		Integer ProvinceId = null;
		if (StringHelper.isNotEmpty(proCode)) {
			HqlFilter hqlFilter = new HqlFilter();
			hqlFilter.addEQFilter("proCode", proCode);

			Province Province = getByFilter(hqlFilter);
			if (Province != null) {
				ProvinceId = Province.getId();
			}
		}
		return ProvinceId;
	}
}
